﻿using L005_ZuoYe.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace L005_ZuoYe.Controllers
{
    public class DefaultController : Controller
    {
        Model1 model = new Model1();

        /// <summary>
        /// 主页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            var taskList = model.Task.ToList();
            return View(taskList);
        }
        /// <summary>
        /// 详情
        /// </summary>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            Task task = model.Task.FirstOrDefault(p => p.TaskID == id);
            return View(task);
        }

        [HttpPost] //指定POST类型访问
        /// <summary>
        /// 删除
        /// </summary>
        /// <returns></returns>
        public ActionResult Delete(int id)
        {
            Task task = model.Task.FirstOrDefault(p => p.TaskID == id);
            if (task!=null)
            {
                model.Task.Remove(task);
                var result = model.SaveChanges() > 0;
                return Json(result);
            }
            return Json(false);
        }
    }
}